package com.gxitsky.enums;

import javafx.scene.shape.VLineTo;

/**
 * @author gxing
 * @desc TODO
 * @date 2023/7/16
 */
public enum SexEnum {

    FEMALE(2, "女"),
    MALE(1, "男"),
    ;

    private int code;
    private String name;

    SexEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static SexEnum getByCode(int code){
        SexEnum[] values = SexEnum.values();
        for (SexEnum value : values) {
            if(value.code == code){
                return value;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        int index = FEMALE.ordinal();
        System.out.println(index);
        Class<SexEnum> sexEnumClass = SexEnum.class;
        SexEnum[] enumConstants = sexEnumClass.getEnumConstants();
        SexEnum enumConstant = enumConstants[index];
        System.out.println(enumConstant);
    }
}
